home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 1 / CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso / Aminet / comm / tcp / AmiTCPsdk_40.lha / AmiTCP-4.0 / src / netlib / _fstat.c < prev    next >
C/C++ Source or Header  |  1994-09-29  |  1KB  |  64 lines

  1. RCS_ID_C="$Id: _fstat.c,v 4.1 1994/09/29 23:09:02 jraja Exp $";
  2. /*
  3.  *      _fstat.c - fstat() for Network Support Library (SAS/C)
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  */
  9.  
  10. #include <sys/types.h>
  11. #include <sys/socket.h>
  12. #include <sys/stat.h>
  13. #include <errno.h>
  14.  
  15. #include <string.h>
  16. #include <stdlib.h>
  17.  
  18. /* DOS 3.0 and MuFS extensions to file info block */
  19. #include "fibex.h"
  20. #include <proto/dos.h>
  21. #include <proto/utility.h>
  22.  
  23. #include <ios1.h>
  24.  
  25. int fstat(int fd, struct stat *st)
  26. {
  27.   struct UFB *ufb = chkufb(fd);
  28.  
  29.   if (st == NULL || ((1 & (long)st) == 1)) {
  30.     errno = EFAULT;
  31.     return -1;
  32.   }
  33.  
  34.   if (ufb == NULL || ufb->ufbflg == 0) {
  35.     errno = EBADF;
  36.     return -1;
  37.   }
  38.  
  39.   if (ufb->ufbflg & UFB_SOCK) { /* a socket */
  40.     long value;
  41.     long size = sizeof(value);
  42.     bzero(st, sizeof(*st));
  43.  
  44.     /* st->st_dev = ??? */
  45.     st->st_mode = S_IFSOCK | S_IRUSR | S_IWUSR;
  46.     st->st_uid = geteuid();
  47.     st->st_gid = getegid();
  48.  
  49.     if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, &size) == 0)
  50.       st->st_blksize = value;
  51.  
  52.     return 0;
  53.   } else { /* ordinal file */
  54.     if (ExamineFH(ufb->ufbfh, __dostat_fib)) {
  55.       __dostat(__dostat_fib, st);
  56.       st->st_dev = (dev_t)((struct FileHandle *)BADDR(ufb->ufbfh))->fh_Type;
  57.       return 0;
  58.     } else {
  59.       errno = EIO;
  60.       return -1;
  61.     }
  62.   }
  63. }
  64.